/*
* EfficiencyController.java
* Created on  2015/5/24 20:15
* 版本       修改时间          作者      修改内容
* V1.0.1    2015/5/24       xfz    初始版本
*
*/

package com.infitecs.eyas.boiler;

import com.infitecs.eyas.boiler.model.AirGasParameter;
import com.infitecs.eyas.boiler.model.Efficiency;
import com.infitecs.eyas.boiler.service.EfficiencyService;
import com.infitecs.eyas.nature.model.Nature;
import com.infitecs.eyas.util.DoubleUtil;
import com.infitecs.krill.ajax.response.AjaxResponse;
import com.infitecs.krill.ajax.response.ReturnState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * 类的描述信息
 *
 * @author xfz
 * @version 1.0.1
 */

@Controller
@RequestMapping("/boiler/efficiency")
public class EfficiencyController {

    @Autowired
    private EfficiencyService efficiencyService;

    @RequestMapping(value = "initialization", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse initialization(HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        efficiencyService.saveTheValueOfCount(caseId);
        double E88 = efficiencyService.calculateTheValueOfE88(caseId);
        double E89 = efficiencyService.calculateTheValueOfE89(caseId);
        double E90 = efficiencyService.calculateTheValueOfE90(caseId);
        double E93 = efficiencyService.calculateTheValueOfE93(caseId);
        double E92 = efficiencyService.calculateTheValueOfE92(caseId);
        double E94 = efficiencyService.calculateTheValueOfE94(caseId);
        double E95 = efficiencyService.calculateTheValueOfE95(caseId);
        double E53 = efficiencyService.calculateTheValueOfE53(caseId);
        double E51 = efficiencyService.calculateTheValueOfE51(caseId);
//        double E52 = efficiencyService.calculateTheValueOfE52(caseId);
        AjaxResponse ajaxResponse = new AjaxResponse();
        ajaxResponse.addAttribute("E88",DoubleUtil.getInstance().get3Double(E88));
        ajaxResponse.addAttribute("E89", DoubleUtil.getInstance().get3Double(E89));
        ajaxResponse.addAttribute("E90",DoubleUtil.getInstance().get3Double(E90));
        ajaxResponse.addAttribute("E93", DoubleUtil.getInstance().get3Double(E93));
        ajaxResponse.addAttribute("E92",DoubleUtil.getInstance().get3Double(E92));
        ajaxResponse.addAttribute("E94", DoubleUtil.getInstance().get3Double(E94));
        ajaxResponse.addAttribute("E95",DoubleUtil.getInstance().get3Double(E95));
        ajaxResponse.addAttribute("E53",DoubleUtil.getInstance().get3Double(E53));
//        ajaxResponse.addAttribute("E52",DoubleUtil.getInstance().get3Double(E52));
        return ajaxResponse;
    }

    @RequestMapping(value = "getAirGasMedian", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse getAirGasMedian(String caseId) {
        int id=Integer.parseInt(caseId);
        return efficiencyService.getAirGasMedian(id);
    }


    @RequestMapping(value = "saveTheValueOfE89", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse saveTheValueOfE89(@RequestParam("E89") double E89, HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        efficiencyService.saveTheValueOfE89(E89, caseId);
        double E90 = efficiencyService.calculateTheValueOfE90(caseId);
        double E93 = efficiencyService.calculateTheValueOfE93(caseId);
        double E92 = efficiencyService.calculateTheValueOfE92(caseId);
        double E94 = efficiencyService.calculateTheValueOfE94(caseId);
        double E95 = efficiencyService.calculateTheValueOfE95(caseId);
        AjaxResponse ajaxResponse = new AjaxResponse();
        ajaxResponse.addAttribute("E89", DoubleUtil.getInstance().get3Double(E89));
        ajaxResponse.addAttribute("E90",DoubleUtil.getInstance().get3Double(E90));
        ajaxResponse.addAttribute("E93", DoubleUtil.getInstance().get3Double(E93));
        ajaxResponse.addAttribute("E92",DoubleUtil.getInstance().get3Double(E92));
        ajaxResponse.addAttribute("E94", DoubleUtil.getInstance().get3Double(E94));
        ajaxResponse.addAttribute("E95",DoubleUtil.getInstance().get3Double(E95));
        return ajaxResponse;
    }

//    @RequestMapping(value = "calculateTheValueOfE89", method = {RequestMethod.POST})
//    @ResponseBody
//    public AjaxResponse calculateTheValueOfE89(HttpSession httpSession) throws ParsingException, EvalException {
//        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
//        double E89 = efficiencyService.calculateTheValueOfE89(caseId);
//        return new AjaxResponse(String.valueOf(DoubleUtil.getInstance().get3Double(E89)));
//    }

    @RequestMapping(value = "saveTheValueOfE90", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse saveTheValueOf90(@RequestParam("E90") double E90, HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        efficiencyService.saveTheValueOfE90(E90, caseId);
        double E93 = efficiencyService.calculateTheValueOfE93(caseId);
        double E92 = efficiencyService.calculateTheValueOfE92(caseId);
        double E94 = efficiencyService.calculateTheValueOfE94(caseId);
        double E95 = efficiencyService.calculateTheValueOfE95(caseId);
        AjaxResponse ajaxResponse = new AjaxResponse();
        ajaxResponse.addAttribute("E93", DoubleUtil.getInstance().get3Double(E93));
        ajaxResponse.addAttribute("E92",DoubleUtil.getInstance().get3Double(E92));
        ajaxResponse.addAttribute("E94", DoubleUtil.getInstance().get3Double(E94));
        ajaxResponse.addAttribute("E95",DoubleUtil.getInstance().get3Double(E95));
        return ajaxResponse;
    }

//    @RequestMapping(value = "calculateTheValueOfE90", method = {RequestMethod.POST})
//    @ResponseBody
//    public AjaxResponse calculateTheValueOfE90(HttpSession httpSession) {
//        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
//        String E90 = String.valueOf(efficiencyService.calculateTheValueOfE90(caseId));
//        return new AjaxResponse(E90);
//    }

    @RequestMapping(value = "calculateTheValueOfE51", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse calculateTheValueOfE51(HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        String E51 = String.valueOf(efficiencyService.calculateTheValueE51(caseId));
        return new AjaxResponse(E51);
    }

    @RequestMapping(value = "calculateTheValueOfE52", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse calculateTheValueOfE52(@RequestParam("e51") double e51,HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        double E52 = efficiencyService.calculateTheValueOfE52(caseId,e51);
        AjaxResponse ajaxResponse = new AjaxResponse();
        ajaxResponse.addAttribute("E52",DoubleUtil.getInstance().get3Double(E52));
        return ajaxResponse;
    }

    @RequestMapping(value = "saveTheValueOfIsKnown", method = {RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfIsKnown(@RequestParam("isKnown") boolean isKnown, HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        efficiencyService.saveTheValueOfIsKnown(isKnown,caseId);
    }

    @RequestMapping(value = "saveTheValueOfE51", method = {RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOf51(@RequestParam("E51") double E51, HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        efficiencyService.saveTheValueOfE51(E51, caseId);
    }

    @RequestMapping(value = "saveTheValueOfE52", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse saveTheValueOf52(@RequestParam("E52") double E52, HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        efficiencyService.saveTheValueOfE52(E52, caseId);
        double E89 = efficiencyService.calculateTheValueOfE89(caseId);
        double E90 = efficiencyService.calculateTheValueOfE90(caseId);
        double E93 = efficiencyService.calculateTheValueOfE93(caseId);
        double E92 = efficiencyService.calculateTheValueOfE92(caseId);
        double E94 = efficiencyService.calculateTheValueOfE94(caseId);
        double E95 = efficiencyService.calculateTheValueOfE95(caseId);
        AjaxResponse ajaxResponse = new AjaxResponse();
        ajaxResponse.addAttribute("E89", DoubleUtil.getInstance().get3Double(E89));
        ajaxResponse.addAttribute("E90",DoubleUtil.getInstance().get3Double(E90));
        ajaxResponse.addAttribute("E93", DoubleUtil.getInstance().get3Double(E93));
        ajaxResponse.addAttribute("E92",DoubleUtil.getInstance().get3Double(E92));
        ajaxResponse.addAttribute("E94", DoubleUtil.getInstance().get3Double(E94));
        ajaxResponse.addAttribute("E95",DoubleUtil.getInstance().get3Double(E95));
        return ajaxResponse;
    }

    @RequestMapping(value = "saveTheValueOfE53", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse saveTheValueOf53(@RequestParam("E53") double E53, HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        efficiencyService.saveTheValueOfE53(E53, caseId);
        double E89 = efficiencyService.calculateTheValueOfE89(caseId);
        double E90 = efficiencyService.calculateTheValueOfE90(caseId);
        double E93 = efficiencyService.calculateTheValueOfE93(caseId);
        double E92 = efficiencyService.calculateTheValueOfE92(caseId);
        double E94 = efficiencyService.calculateTheValueOfE94(caseId);
        double E95 = efficiencyService.calculateTheValueOfE95(caseId);
        AjaxResponse ajaxResponse = new AjaxResponse();
        ajaxResponse.addAttribute("E89", DoubleUtil.getInstance().get3Double(E89));
        ajaxResponse.addAttribute("E90",DoubleUtil.getInstance().get3Double(E90));
        ajaxResponse.addAttribute("E93", DoubleUtil.getInstance().get3Double(E93));
        ajaxResponse.addAttribute("E92",DoubleUtil.getInstance().get3Double(E92));
        ajaxResponse.addAttribute("E94", DoubleUtil.getInstance().get3Double(E94));
        ajaxResponse.addAttribute("E95",DoubleUtil.getInstance().get3Double(E95));
        return ajaxResponse;
    }

    @RequestMapping(value = "saveTheValueOfE54", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse saveTheValueOfE54(@RequestParam("E54") double E54, HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        efficiencyService.saveTheValueOfE54(E54, caseId);
        double E89 = efficiencyService.calculateTheValueOfE89(caseId);
        double E90 = efficiencyService.calculateTheValueOfE90(caseId);
        double E93 = efficiencyService.calculateTheValueOfE93(caseId);
        double E92 = efficiencyService.calculateTheValueOfE92(caseId);
        double E94 = efficiencyService.calculateTheValueOfE94(caseId);
        double E95 = efficiencyService.calculateTheValueOfE95(caseId);
        AjaxResponse ajaxResponse = new AjaxResponse();
        ajaxResponse.addAttribute("E89", DoubleUtil.getInstance().get3Double(E89));
        ajaxResponse.addAttribute("E90",DoubleUtil.getInstance().get3Double(E90));
        ajaxResponse.addAttribute("E93", DoubleUtil.getInstance().get3Double(E93));
        ajaxResponse.addAttribute("E92",DoubleUtil.getInstance().get3Double(E92));
        ajaxResponse.addAttribute("E94", DoubleUtil.getInstance().get3Double(E94));
        ajaxResponse.addAttribute("E95",DoubleUtil.getInstance().get3Double(E95));
        return ajaxResponse;
    }

    @RequestMapping(value = "saveTheValueOfE88", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse saveTheValueOfE88(@RequestParam("E88") double E88, HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        efficiencyService.saveTheValueOfE88(E88, caseId);
        double E89 = efficiencyService.calculateTheValueOfE89(caseId);
        double E90 = efficiencyService.calculateTheValueOfE90(caseId);
        double E93 = efficiencyService.calculateTheValueOfE93(caseId);
        double E92 = efficiencyService.calculateTheValueOfE92(caseId);
        double E94 = efficiencyService.calculateTheValueOfE94(caseId);
        double E95 = efficiencyService.calculateTheValueOfE95(caseId);
        AjaxResponse ajaxResponse = new AjaxResponse();
        ajaxResponse.addAttribute("E89", DoubleUtil.getInstance().get3Double(E89));
        ajaxResponse.addAttribute("E90",DoubleUtil.getInstance().get3Double(E90));
        ajaxResponse.addAttribute("E93", DoubleUtil.getInstance().get3Double(E93));
        ajaxResponse.addAttribute("E92",DoubleUtil.getInstance().get3Double(E92));
        ajaxResponse.addAttribute("E94", DoubleUtil.getInstance().get3Double(E94));
        ajaxResponse.addAttribute("E95",DoubleUtil.getInstance().get3Double(E95));
        return ajaxResponse;
    }

    @RequestMapping(value = "saveTheValueOfE92", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse saveTheValueOfE92(@RequestParam("E92") double E92, HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        efficiencyService.saveTheValueOfE92(E92, caseId);
        double E94 = efficiencyService.calculateTheValueOfE94(caseId);
        double E95 = efficiencyService.calculateTheValueOfE95(caseId);
        AjaxResponse ajaxResponse = new AjaxResponse();
        ajaxResponse.addAttribute("E92",DoubleUtil.getInstance().get3Double(E92));
        ajaxResponse.addAttribute("E94", DoubleUtil.getInstance().get3Double(E94));
        ajaxResponse.addAttribute("E95",DoubleUtil.getInstance().get3Double(E95));
        return ajaxResponse;
    }

    @RequestMapping(value = "saveTheValueOfE93", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse saveTheValueOfE93(@RequestParam("E93") double E93, HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        efficiencyService.saveTheValueOfE93(E93, caseId);
        double E92 = efficiencyService.calculateTheValueOfE92(caseId);
        double E94 = efficiencyService.calculateTheValueOfE94(caseId);
        double E95 = efficiencyService.calculateTheValueOfE95(caseId);
        AjaxResponse ajaxResponse = new AjaxResponse();
        ajaxResponse.addAttribute("E93", DoubleUtil.getInstance().get3Double(E93));
        ajaxResponse.addAttribute("E92",DoubleUtil.getInstance().get3Double(E92));
        ajaxResponse.addAttribute("E94", DoubleUtil.getInstance().get3Double(E94));
        ajaxResponse.addAttribute("E95",DoubleUtil.getInstance().get3Double(E95));
        return ajaxResponse;
    }

    @RequestMapping(value = "saveTheValueOfE94", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse saveTheValueOfE94(@RequestParam("E94") double E94, HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        efficiencyService.saveTheValueOfE94(E94, caseId);
        double E95 = efficiencyService.calculateTheValueOfE95(caseId);
        AjaxResponse ajaxResponse = new AjaxResponse();
        ajaxResponse.addAttribute("E94", DoubleUtil.getInstance().get3Double(E94));
        ajaxResponse.addAttribute("E95",DoubleUtil.getInstance().get3Double(E95));
        return ajaxResponse;
    }

    @RequestMapping(value = "saveTheValueOfE95", method = {RequestMethod.POST})
    @ResponseBody
    public void saveTheValueOfE95(@RequestParam("E95") double E95, HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        efficiencyService.saveTheValueOfE95(E95, caseId);
    }

    @RequestMapping(value = "calculateTheValueOfE93", method = {RequestMethod.POST})
    @ResponseBody
    public List<String> calculateTheValueOfE93(HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        double E93 = efficiencyService.calculateTheValueOfE93(caseId);
        double E92 = efficiencyService.calculateTheValueOfE92(caseId);
        double E94 = efficiencyService.calculateTheValueOfE94(caseId);
        double E95 = efficiencyService.calculateTheValueOfE95(caseId);
        List<String> result = new ArrayList<>();
        result.add(String.valueOf(DoubleUtil.getInstance().get3Double(E93)));
        result.add(String.valueOf(DoubleUtil.getInstance().get3Double(E92)));
        result.add(String.valueOf(DoubleUtil.getInstance().get3Double(E94)));
        result.add(String.valueOf(DoubleUtil.getInstance().get3Double(E95)));
        return result;
    }

    @RequestMapping(value = "calculateTheValueOfE92", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse calculateTheValueOfE92(HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        double E92 = efficiencyService.calculateTheValueOfE92(caseId);
        return new AjaxResponse(String.valueOf(DoubleUtil.getInstance().get3Double(E92)));
    }

    @RequestMapping(value = "calculateTheValueOfE94", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse calculateTheValueOfE94(HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        double E94 = efficiencyService.calculateTheValueOfE94(caseId);
        return new AjaxResponse(String.valueOf(DoubleUtil.getInstance().get3Double(E94)));
    }

    @RequestMapping(value = "calculateTheValueOfE95", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse calculateTheValueOfE95(HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        double E95 = efficiencyService.calculateTheValueOfE95(caseId);
        return new AjaxResponse(String.valueOf(DoubleUtil.getInstance().get3Double(E95)));
    }

    @RequestMapping(value = "calculateTheValueOfE53", method = {RequestMethod.POST})
    @ResponseBody
    public AjaxResponse calculateTheValueOfE53(HttpSession httpSession) {
        int caseId = Integer.parseInt(httpSession.getAttribute("caseId").toString());
        double E53 = efficiencyService.calculateTheValueOfE53(caseId);
        return new AjaxResponse(String.valueOf(DoubleUtil.getInstance().get3Double(E53)));
    }

    @RequestMapping(value = "recover", method = RequestMethod.GET)
    @ResponseBody
    public Efficiency getEfficiency(HttpSession session) {
        int caseId = Integer.parseInt(session.getAttribute("caseId").toString());
        return efficiencyService.getEfficiency(caseId);
    }

    @RequestMapping(value = "efficiencySave", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResponse efficiencySave(Efficiency efficiency) {
        try {
            efficiencyService.efficiencySave(efficiency);
            return new AjaxResponse();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResponse(ReturnState.ERROR, "请检查填写数据是否有误，操作失败");
        }
    }
}
